package com.e3.bill.client;

import java.util.ArrayList;
import java.util.List;

import com.e3.bill.model.BillMainModel;
import com.e3.bill.model.BillStatus;
import com.e3.web.widget.client.MyFormFieldFactory;
import com.e3.web.widget.model.ListTypeModel;
import com.extjs.gxt.ui.client.widget.form.Field;

public class BillHelper {
	
	public static BillHelper INSTANCE = new BillHelper();
	
	public Field<?> createFormField(String name){
		Field<?> formField = null;
		String dispName = getFormFieldDisplayName(name);

		if (name.equals(BillMainModel.ID)||name.equals(BillMainModel.CREATE_USER_ID)
				||name.equals(BillMainModel.MODIFY_USER_ID)||name.equals(BillMainModel.APPROVER_ID)) {
			formField = MyFormFieldFactory.createIdField(name);
		}
		else if(name.equals(BillMainModel.BILLNO)){
			formField = MyFormFieldFactory.createStringField(name, dispName, 50, false);
		}
		else if(name.equals(BillMainModel.CREATE_USER)||name.equals(BillMainModel.MODIFY_USER)
				||name.equals(BillMainModel.APPROVER)){
			formField = MyFormFieldFactory.createStringField(name, dispName, 50, false);
		}
		else if(name.equals(BillMainModel.CREATE_TIME)||name.equals(BillMainModel.MODIFY_TIME)
				||name.equals(BillMainModel.APPROVE_TIME)){
			formField = MyFormFieldFactory.createDateField(name, dispName, true);
		}
		else if(name.equals(BillMainModel.STATUS)){
			List<ListTypeModel<Integer>> listValueModels = new ArrayList<ListTypeModel<Integer>>();
			// 
			listValueModels.add(new ListTypeModel<Integer>(BillStatus.SAVED, BillFieldsConstant.INSTANCE.status_saved()));
			listValueModels.add(new ListTypeModel<Integer>(BillStatus.APPROVING, BillFieldsConstant.INSTANCE.status_approving()));
			listValueModels.add(new ListTypeModel<Integer>(BillStatus.APPROVE_PASS, BillFieldsConstant.INSTANCE.status_approve_pass()));
			listValueModels.add(new ListTypeModel<Integer>(BillStatus.APPROVE_NOPASS, BillFieldsConstant.INSTANCE.status_approve_nopass()));
			listValueModels.add(new ListTypeModel<Integer>(BillStatus.OBSOLETE, BillFieldsConstant.INSTANCE.status_obsolete()));
			formField = MyFormFieldFactory.createListField(name, dispName, listValueModels, true, true);
		}
		else if(name.equals(BillMainModel.REMARK)){
			formField = MyFormFieldFactory.createTextAreaField(name, dispName, 100, true);
		}
		return formField;
	}

	private String getFormFieldDisplayName(String name) {
		return BillFieldsConstant.INSTANCE.getString(name);
	}

}
